package com.eye.web.controller.manage;

import com.eye.system.domain.Location;
import com.eye.system.search.LocationSearch;
import com.eye.system.service.LocationService;
import com.eye.system.util.PageResult;
import com.eye.system.util.Results;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/location/")
@Api(tags = "地点")
public class LocationController {
    @Autowired
    private LocationService locationService;

    @PostMapping("add")
    @ApiOperation("新增地点")
    public Results addLocation(@RequestBody Location location) {
        Integer addLocation = locationService.addLocation(location);
        return Results.ok(addLocation);
    }

    @PostMapping("select/paging")
    @ApiOperation("分页条件查询地点")
    public Results selectPaging(@RequestBody LocationSearch locationSearch) {
        PageResult pageResult = locationService.selectPaging(locationSearch);
        return Results.ok(pageResult);
    }

    @PostMapping("delete")
    @ApiOperation("根据ID删除地点")
    public Results deleteLocation(@RequestParam Integer id) {
        Integer deleteLocation = locationService.deleteLocation(id);
        return Results.ok(deleteLocation);
    }

    @GetMapping("select")
    @ApiOperation("根据ID查询地点")
    public Results selectById(@RequestParam Integer id) {
        Location location = locationService.selectById(id);
        return Results.ok(location);
    }

    @PostMapping("update")
    @ApiOperation("根据ID修改地点")
    public Results updateById(@RequestParam Integer id, @RequestBody Location location) {
        Integer updateLocation = locationService.updateLocation(id, location);
        return Results.ok(updateLocation);
    }
}
